from typing import Callable
import os
import baseFrame as bf
import baseButton as btn
import wxSession as sess
import textProcess as tp
import threading as th


def wxSess() -> None:
    wxSess: sess.wxSession = sess.wxSession()
    textProc: tp.textProcess = tp.textProcess(fileLoad=r'./dialog.txt')
    textProc.ReadText()
    wxSess.Session(keyword=textProc.diaDict)


def ProtTh(func: Callable[[], None]) -> None:
    protTh: th.Thread = th.Thread(target=func)
    protTh.setDaemon(True)
    protTh.start()


def OpenFile(fileLoad: str) -> None:
    os.startfile(fileLoad)



class mainFrame(bf.baseFrame):
    def __init__(self) -> None:
        super().__init__()
    

    def Show(self):
        super().Show('微信机器人')


        startBtn: btn.baseButton= btn.baseButton(self.window, text='开始运行', command=lambda: ProtTh(wxSess))
        startBtn.Position(position_x=200, position_y=100, width=200)


        modifyBtn: btn.baseButton= btn.baseButton(self.window, text='修改关键词', command=lambda: ProtTh(OpenFile(r'dialog.txt')))
        modifyBtn.Position(position_x=200, position_y=170, width=200)


        self.window.mainloop()


if __name__ == '__main__':
    mf: mainFrame = mainFrame()
    mf.Show()
